package cn.zhaoyuening.lucenedemo2.web.controller;

import cn.zhaoyuening.lucenedemo2.domain.News;
import cn.zhaoyuening.service.IndexsService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.IOException;
import java.util.List;

/**
 * Created by Zhao on 2017/2/26.
 */
@Controller
@RequestMapping("/indexs/")
public class IndexsController {
    private IndexsService indexsService;

    @Autowired
    public void setIndexsService(IndexsService indexsService) {
        this.indexsService = indexsService;
    }
    @RequestMapping("search.do")
    public String search(@RequestParam(value = "title",required = false)String title, Model model) throws IOException {
        if (!StringUtils.isEmpty(title)){
            List<News> newsList = indexsService.findByTitle(title);
            model.addAttribute("newsList", newsList);
        }
        return "searchResult";
    }
}
